# -*- coding: UTF-8 -*-
from dataclasses import dataclass, field

from wtforms import Form

from core.dto.error import ErrorDTO, ErrorsDTO


class BaseForm(Form):
    def __init__(self, data=None):
        Form.__init__(self, data=data)

    def errors_dto(self):
        errors_dto = ErrorsDTO()
        for error_name, error_message in self.errors.items():
            errors_dto.errors.append(
                ErrorFieldDTO(field_name=error_name, message=error_message)
            )
        return errors_dto


@dataclass
class ErrorFieldDTO(ErrorDTO):
    field_name: str = field(default="")
